package com.atguigu.gmall.product;

import com.atguigu.gmall.common.constant.RedisConst;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan({"com.atguigu.gmall"})
@EnableDiscoveryClient
public class ProductApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProductApplication.class,args);
    }

    @Autowired
    private RedissonClient redissonClient;

    /**
     * RedissonClient:这个框架里边就有过滤器的方法,直接获取就行,里边的参数是"sku:bloom:filter",这里放到常量类里边了
     * bloomFilter.tryInit(100000,0.01);设置布隆过滤器的策略
     * 这里设置好之后,就可以在填加数据的代码那儿引用这个过滤器存id了
     * 然后在查询的时候,布隆就会根据id与存的值进行比较,存在才会继续执行,不存在就不让过了(看门狗)
     * 有效的防止了缓存穿透问题(缓存穿透指大量的数据库中没有的id的请求(比如恶意攻击))
     *
     * implements CommandLineRunner :需要继承这个类
     *
     * @Override
     *     public void run(String... args) throws Exception {
     *
     *         System.out.println("初始化,设置布隆过滤器的策略");
     *         RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
     *         bloomFilter.tryInit(100000,0.01);
     *     }
     *
     */



}
